package com.oristartech.xxlconf.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.xxl.conf.core.spring.XxlConfFactory;

@Configuration
@ConditionalOnProperty(prefix = "xxl.conf",value = "enabled",matchIfMissing = false)
public class XxlconfAutoConfiguration {
    
    @Autowired
    private XxlConfProperties xxlConfProperties;
    
    @Bean
    @ConditionalOnMissingBean(XxlConfFactory.class)
    public XxlConfFactory xxlConfFactory() {
        XxlConfFactory xxlConf = new XxlConfFactory();
        xxlConf.setAdminAddress(xxlConfProperties.getAdminAddress());
        xxlConf.setEnv(xxlConfProperties.getEnv());
        xxlConf.setAccessToken(xxlConfProperties.getAccessToken());
        xxlConf.setMirrorfile(xxlConfProperties.getMirrorfile());
        return xxlConf;
    }
}
